#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n,m,l,vm,ans1,ans2;

struct sensor
{
	int pos,num;
	vector<int> list;
}p[MAXN];

struct vehicle
{
	int pos,v,a,d,l,r;
	bool vis;
}car[MAXN];

void insert(vehicle x)
{
	int y = 1;
	while(x.r > p[y].pos)
	{
		if(x.l <= p[y].pos)
		{
			p[y].num++;
			p[y].list[p[y].num] = x.pos;
			x.vis = true;
		}	
	}
}

int main()
{
	int t;
	cin>>t;
	for(int subtask = 1;subtask <= t;subtask++)
	{
		cin>>n>>m>>l>>vm;
		for(int i = 1;i <= n;i++)
		{
			cin>>car[i].d>>car[i].v>>car[i].a;
			car[i].l = 0;
			car[i].r = 0;
			car[i].vis = 0;
		}
		for(int i = 1;i <= m;i++)
		{
			cin>>p[i].pos;
			p[i].num = 0;
		}
		for(int i = 1;i <= n;i++)
		{
			vehicle now = car[i];
			if(!now.a)
			{
				if(now.v > vm)
				{
					now.l = now.d;
					now.r = l;
				}
			}
			else if(now.a > 0)
			{
				if(now.v > vm)
				{
					now.l = now.d;
					now.r = l;
				}
				else if(now.v == vm)
				{
					now.l = now.d + 1;
					now.r = l;
				}
				else
				{
					int s;
					if(!((vm*vm-now.v*now.v)%now.a))
						s = (vm*vm-now.v*now.v)/now.a - 1;
					else    s = (vm*vm-now.v*now.v)/now.a;
					if((now.d + s) < l)
					{
						now.l = now.d + s;
						now.r = l;
					}
				}
			}
			else
			{
				if(now.v > vm)
				{
					int s;
					if(!((now.v*now.v-vm*vm)%(0-now.a)))
						s = (vm*vm-now.v*now.v)/now.a - 1;
					else    s = (vm*vm-now.v*now.v)/now.a;
					if((now.d + s) < l)
					{
						now.l = now.d;
						now.r = now.d + s;
					}
				}
			}
			insert(now);
		}
		for(int i = 1;i <= n;i++)
			if(car[i].vis)
				ans1++;
		cout<<ans1<<" "<<m-ans1<<endl;
	}
	return 0;
}

